package com.wl.service.Impl;

import com.wl.mapper.LoginMapper;
import com.wl.pojo.User;
import com.wl.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    /**
     * 后台账号密码登陆接口
     * @param user 实体类
     * @return 返回用户id和jwt令牌
     */
    @Override
    public User getUserInfo(User user) {
        return loginMapper.getUserInfo(user);
    }

    /**
     * 根据ID获取用户信息
     */
    @Override
    public User getUserInfoById(Integer userId) {
        return loginMapper.getUserInfoById(userId);
    }

    /**
     * 注册
     */
    @Override
    public User addUserInfo(User user) {
        user.setCreateTime(LocalDateTime.now());
        loginMapper.addUserInfo(user);
        return loginMapper.getUserInfo(user);
    }
}
